package com.steerinfo.dil.util;

import com.steerinfo.dil.feign.ColumnDataFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;

@Component
public class ColumnDataUtil {
    @Autowired
    ColumnDataFeign columnDataFeign;

    private Set<Map<String, Object>> setListMap(List<Map<String, Object>> list, String name) {
        Set<Map<String, Object>> setString = new HashSet<>();
        for (Map<String, Object> map : list) {//遍历每条数据
            Map<String, Object> map1 = new HashMap<>();
            //map.get(name)获取每条数据中对应表头字段的数据
            map1.put("text", map.get(name));
            if (map.get(name) != null) {
                map1.put("value", map.get(name));
                setString.add(map1);
            }
        }
        return setString;
    }

    public PageListAdd tableColumnData(Integer apiId, List<Map<String,Object>> data) {
        List<Map<String, Object>> columnDataList = columnDataFeign.getColumnData(apiId);
        for (Map<String, Object> columnData : columnDataList) {
            //每个表头字段的过滤条件
            columnData.put("filters", setListMap(data, columnData.get("prop").toString()));
        }
        PageListAdd pageList = new PageListAdd(data);
        pageList.setColumnData(columnDataList);
        return pageList;
    }
}
